package com.doit.day01;

import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;

import java.io.IOException;
import java.util.List;

public class NameNodeDemo {
    public static void main(String[] args) throws Exception {

        String zkConnect = "linux01:2181,linux02:2181,linux03:2181";
        int timeOut = 1000;
        ZooKeeper zk = new ZooKeeper(zkConnect, timeOut, new Watcher() {
            @Override
            public void process(WatchedEvent event) {
                System.out.println("nameDode开始工作了......");
            }
        });

        String path=  "/datanodes";

        zk.getChildren(path, new Watcher() {
            @Override
            public void process(WatchedEvent event) {
                try {
                    List<String> children = zk.getChildren(path, this);
                    System.out.println("namenode监听到datanode的个数有变化了，现在开始重新获取datanode的子节点情况：");
                    for (String child : children) {
                        System.out.println("子节点有："+child);
                    }
                    System.out.println("重新获取到子节点个数之后，该干嘛干嘛，比如复制，移动block块，保证数据有三个副本");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });

        Thread.sleep(100000000);




    }
}
